import React, { useEffect, useState } from 'react';

/**
 * @Leon 模拟订阅和取消订阅
 */
export default function EffectHookCancelDemo() {

    const [count, setCount] = useState(0);

    useEffect(() => {
        console.log('订阅事件');

        // 当前函数的返回值又是一个函数
        return () => {
            console.log('取消订阅');
        }
        // 数组为了让+1不在来回订阅和取消事件
    }, []) 



    return (
        <div>
            <h2>EffectHookCancelDemo</h2>
            {count}
            <button onClick={e => setCount(count + 1)}>+1</button>
        </div>
    )
}